package Problem;

import MiddlePane.Single_choice;

import javax.swing.*;
import java.io.FileNotFoundException;

/**
 * Creat with IntelliJ IDEA
 * Description:题库
 * Date:2021-12-13
 * Time:22:36
 */
public class QuestionBank implements Runnable{

    public static boolean flg;//记录是否出完题目 - 默认为false
    public static int scq = 0;//single choice question - 记录已出单选题数量
    public static int mcq = 0;//multiple choice question - 记录已出多选题数量
    public static int jq = 0;//judgement question - 记录已出判断题数量
    public static Problem[] problems = new Problem[3];

    public QuestionBank() throws FileNotFoundException {

        problems[0] = new Single_choice_question();
        problems[1] = new mutiple_choice_question();
        problems[2] = new judgement_question();
    }

    public static Box setQuestion(){
        int type = (int)(Math.random()*5);
        if(type==0 && scq!=5){//出单选题
            scq++;
            //随机抽取单选题题号
            int number = (int)(Math.random()*10);
            //获取题目信息
            String q = problems[0].question(number).getQ();
            String[] c = problems[0].question(number).getChoice();
            //生成单选题做题界面
            Single_choice single_choice = new Single_choice(q,c[0],c[1],c[2],c[3]);
            return single_choice.getquestionSetting();
        }else if (type==1 && mcq!=5){//出多选题
            mcq++;
            int number = (int)(Math.random()*10);
            System.out.println(problems[1].question(number));
        }else if (jq!=5){//出判断题
            jq++;
            int number = (int)(Math.random()*10);
            System.out.println(problems[2].question(number));
        }
        if(scq==5 && mcq==5 && jq==5){
            flg = true;
        }
        return null;
    }

    @Override
    public void run() {
            try {
                while(!flg){
                    setQuestion();
                    wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

    }
}
